/******************************************************************************
 * Copyright (C) 2015  671643387@qq.com
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 *****************************************************************************/

#ifndef SHARED_BASE_THREAD_H_
#define SHARED_BASE_THREAD_H_

#ifdef __WIN32__
#include "Shared/Base/Thread_WIN32.h"
#else
#error
#endif


class Runnable;

class Thread: private ThreadImpl
{
public:
	typedef ThreadImpl::ID	ID;

	enum Priority
	{
		PRIO_LOWEST  = PRIO_LOWEST_IMPL,
		PRIO_LOW     = PRIO_LOW_IMPL,
		PRIO_NORMAL  = PRIO_NORMAL_IMPL,
		PRIO_HIGH    = PRIO_HIGH_IMPL,
		PRIO_HIGHEST = PRIO_HIGHEST_IMPL
	};

	Thread(Runnable *runnable);
	~Thread(void);


	bool start(void);
	void join(void);
	bool joinable(void);

	bool setPriority(int priority);

	ID id(void) const;

	static ID currentThreadId(void);
	static void sleep(long miliseconds);
};


inline bool Thread::start(void)
{
	return startImpl();
}

inline void Thread::join(void)
{
	return joinImpl();
}

inline bool Thread::joinable(void)
{
	return joinableImpl();
}

inline bool Thread::setPriority(int priority)
{
	return setPriorityImpl(priority);
}

inline Thread::ID Thread::id(void) const
{
	return idImpl();
}

inline Thread::ID Thread::currentThreadId(void)
{
	return currentThreadIdImpl();
}

inline void Thread::sleep(long miliseconds)
{
	return sleepImpl(miliseconds);
}

#endif /* SHARED_BASE_THREAD_H_ */
